package com.atguigu.gulimall.order.vo;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.List;
import java.util.Map;

/**
 * @DESCRIPTION: 订单确认VO
 * @author: zr
 * @DATE: 2023/3/7 23:01
 */
public class OrderConfirmVo {

    /**
     * 收货地址列表
     */
    @Getter
    @Setter
    private List<MemberAddressVo> memberAddressVos;

    /**
     * 送货清单，根据购物车页面传递过来的skuIds查询
     */
    @Getter
    @Setter
    private List<OrderItemVo> items;

    /**
     * 用户的购物积分信息，ums_member表中的integration字段
     */
    @Getter
    @Setter
    private Integer integration;

    /**
     * 订单总额
     */
    private BigDecimal total;
    @Getter
    @Setter
    Map<Long, Boolean> stocks;

    /**
     * 数量
     */
    private Integer count;

    private Integer getCount() {
        Integer count = 0;
        if (!CollectionUtils.isEmpty(items)) {
            for (OrderItemVo item : items) {
                count += item.getCount();
            }
        }
        return count;
    }

    public BigDecimal getTotal() {
        BigDecimal sum = new BigDecimal("0");
        if (!CollectionUtils.isEmpty(items)) {
            for (OrderItemVo item : items) {
                BigDecimal multiply = item.getPrice().multiply(new BigDecimal(item.getCount().toString()));
                sum = sum.add(multiply);
            }
        }
        return sum;
    }

    public BigDecimal getPayPrice() {
        return getTotal();
    }

    /**
     * 应付价格
     */
//    private BigDecimal payPrice;
    /**
     * 防止重复提交的令牌
     */
    @Getter
    @Setter
    private String orderToken;
}
